可连接ORACL/DB2/MYSQL正删改查,可保存多连接
private void 新增数据库ToolStripMenuItem_Click(object sender, EventArgs e)
{
label3.Text = "";
textBox2.Text = "";
DatabaseAdd frm = new DatabaseAdd(this);
frm.changetext_event = new DatabaseAdd.changetext(frm_changetext_event);
frm.Show(this);
}
private void frm_changetext_event(string text)
{
ListViewItem lit = new ListViewItem();
lit.Text = text;
listView1.Items.Add(lit);
comboBox1.Items.Add(lit.Text);
}
private void 删除数据库ToolStripMenuItem_Click(object sender, EventArgs e)
{
label3.Text = "";
textBox2.Text = "";
string sPartNo = "";
ListView.SelectedIndexCollection indexes = this.listView1.SelectedIndices;
if (indexes.Count > 0)
{
int index = indexes[0];
sPartNo = this.listView1.Items[index].SubItems[0].Text;//获取第一列的值
listView1.Items[index].Remove();
comboBox1.Items.Remove(sPartNo);
}
System.IO.File.Delete(System.IO.Directory.GetCurrentDirectory() "\\" "datainfo" "\\" sPartNo ".txt");
}
private void 编辑数据库ToolStripMenuItem_Click(object sender, EventArgs e)
{
DatabaseInfo dbi = new DatabaseInfo();
ClintInfo ci = new ClintInfo();
string sPartNo = "";
int index = 0;
try
{
ListView.SelectedIndexCollection indexes = this.listView1.SelectedIndices;
if (indexes.Count > 0)
{
index = indexes[0];
sPartNo = this.listView1.Items[index].SubItems[0].Text;//获取第一列的值
string text = System.IO.File.ReadAllText(System.IO.Directory.GetCurrentDirectory() "\\" "datainfo" "\\" sPartNo ".txt");
Dictionary<string, string> jsonDict = JsonConvert.DeserializeObject<Dictionary<string, string>>(text);
dbi.contentstring= jsonDict["链接"].ToString();
dbi.contenttype= jsonDict["类型"].ToString();
ci.Othername = sPartNo;
ci.db = dbi;
}
}
catch (Exception ex)
{
getFileList();
MessageBox.Show("操作失败!\n" ex.Message, "提示", MessageBoxButtons.OK,
MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
}
DatabaseAdd frm = new DatabaseAdd(ci);
frm.changetext_event = new DatabaseAdd.changetext(frm_changetext_event);
frm.Show(this);
}
//获取文件夹
void getFileList()
{
string filename = System.IO.Directory.GetCurrentDirectory() "\\" "datainfo";
if (! Directory.Exists(filename))
{
Directory.CreateDirectory(filename);
}
string[] files = Directory.GetFiles(filename, "*.txt");
for (int i = 0; i < files.Length; i )
{
ListViewItem lit = new ListViewItem();
lit.Text= Path.GetFileName(files[i].ToString()).Replace(".txt","");
listView1.Items.Add(lit);
comboBox1.Items.Add(lit.Text);
}
}
private void listView1_SelectedIndexChanged(object sender, EventArgs e)
{
string sPartNo = "";
int index=0;
try
{
ListView.SelectedIndexCollection indexes = this.listView1.SelectedIndices;
if (indexes.Count > 0)
{
index = indexes[0];
sPartNo = this.listView1.Items[index].SubItems[0].Text;//获取第一列的值
string text = System.IO.File.ReadAllText(System.IO.Directory.GetCurrentDirectory() "\\" "datainfo" "\\" sPartNo ".txt");
Dictionary<string, string> jsonDict = JsonConvert.DeserializeObject<Dictionary<string, string>>(text);
label3.Text = jsonDict["类型"].ToString();
textBox2.Text = jsonDict["链接"].ToString();
}
}
catch (Exception ex)
{
listView1.Items[index].Remove();
System.IO.File.Delete(System.IO.Directory.GetCurrentDirectory() "\\" "datainfo" "\\" sPartNo ".txt");
getFileList();
MessageBox.Show("操作失败!\n" ex.Message, "提示", MessageBoxButtons.OK,
MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
}
}
评论